/*
 * @Descripttion: 
 * @version: 
 * @Author: ldh
 * @Date: 2020-05-16 17:04:25
 * @LastEditors: ldh
 * @LastEditTime: 2020-06-16 21:42:40
 */ 
import create from '../store/create.js'
import store from '../store/index.js'

create(store,{
  data:{
    test:'',
    test3:'',
    dateStr:'',
    formatDateStr:'',
  },
  onLoad(){
    let time = new Date('2020/06/16 12:20:50')

    this.formatDate(time,true)
  },
  onShow(){
    if (typeof this.getTabBar === 'function' &&
        this.getTabBar()) {
        this.getTabBar().setData({
          selected: 0
        })
    }
  },
  onChangeTitle(){
    this.$store.test = '修改title成功'+Math.floor(Math.random()*1000)
    this.update()
  },
  onChangeGlobalData(){
    let random = Math.floor(Math.random()*1000)
    this.update({
      test2:random,
      test4:random
    })
  },
  formatDate(time,hasWeek){
    let d = new Date(time) , dateStr = ''
    let [year,month,date,week,h,m] = [
      d.getFullYear(),
      d.getMonth()+1,
      d.getDate(),
      d.getDay(),
      d.getHours(),
      d.getMinutes(),
    ]
    if(month<10) month = '0'+month
    if(date <10) date = '0'+date
    if(h<10) h = '0'+h
    if(m<10) m = '0'+m
    if(hasWeek){
      let weeks = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六',]
      dateStr = [[year,month,date].join('-'),weeks[week],[h,m].join(':')].join(' ')
    }else{
      dateStr = [[year,month,date].join('-'),[h,m].join(':')].join(' ')
    }
    this.setData({
      dateStr
    })
  }
})
// Component({
//   pageLifetimes: {
//     show() {
//       if (typeof this.getTabBar === 'function' &&
//         this.getTabBar()) {
//         this.getTabBar().setData({
//           selected: 0
//         })
//       }
//     }
//   }
// })
